﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NeuralNetwork;
using NeuralNetwork.OutputTypes;
using NeuralNetwork.Neurons;

namespace NeuralNetwork.Layers
{
    public class Pattern
    {
        public DateTime t = DateTime.Now;
        public List<Output> items = null;

        public Pattern(List<Neuron> neurons)
        {
            foreach (Neuron n in neurons)
            {
                if (n.Update())
                {
                    if (items == null) items = new List<Output>();
                    if (n is OutputNeuron) items.Add(((OutputNeuron)n).Output);
                }
            }
        }

    }

    public class SpikingOutputLayer : OutputLayer 
    {
        private Pattern firstSpike = null;

        public SpikingOutputLayer(Network network): base(network)
        {

        }

        public SpikingOutputLayer(Network network, List<Output> outputs, string neurontype): base(network, outputs, neurontype)
        { 
        
        }       

        public override void Reset()
        {
            base.Reset();
            firstSpike = null;
        }

        public override void Update()
        {
            if (firstSpike == null)
            {
                Pattern pattern = new Pattern(neurons);
                if (pattern.items != null) firstSpike = pattern;
            }
        }
    }
}
